class SuccessView extends zysx.BaseView{
	
	private left_btn:eui.Button;

	private next_btn:eui.Button;
	
	private time:eui.Label;

	private rank:eui.Label;

	private title:eui.Label;
	
	private text_tip:eui.Label;


	private giftGroup:eui.Group;

	private gift:eui.Image;

 	public constructor(data?) {
		super(data);
		this.skinName = "SuccessSkin";
	}

	public initComponent(): void {
			super.initComponent();
	}

	public initListener(): void {
		super.initListener();
		
		this.addEvent(this.left_btn, egret.TouchEvent.TOUCH_TAP, this.leftFun, this);
		this.addEvent(this.next_btn, egret.TouchEvent.TOUCH_TAP, this.next, this);
	}

	public onOpen(data?): void {
		super.onOpen(data);
		this.initView();
		
	}

	private initView(): void{
		this.checkGift();
		this.time.text = "用时"+this.data.time+"秒";
		this.rank.text = "你已超过全国"+this.data.rank+"%的用户";
		this.title.text =  CommonData.zhangJie[this.data.chapter-1].name+"第"+this.data.chapter+"章第"+ this.data.level+"关";
		if(this.data.level < 3){
			this.text_tip.visible = true;
		}
	}

		//检查新手礼包
	private checkGift():void{
		let nowDate  = new Date();
		let key = nowDate.getFullYear().toString() + nowDate.getMonth().toString() + nowDate.getDate().toString();
		if(UserMgr.ins.giftTime != key){
			this.addEvent(this.giftGroup,egret.TouchEvent.TOUCH_TAP, this.openView, this);
			this.giftGroup.visible = true;
			var tw = egret.Tween.get( this.gift, { loop:true} );
			tw.to({rotation:-20},120)
				.to({rotation:20},240)
				.to({rotation:-20},360)
				.to({rotation:0},480).wait(3600);

			zysx.LayerMgr.ins.openView(ViewConst.FULIVIEW, 1, LayerType.POP);	
		}
	}

	public leftFun():void{
		var that = this;
		ShareMgr.share({callback(){
			zysx.LayerMgr.ins.openView(ViewConst.PLAYVIEW,1,LayerType.UI);
			that.closeSelf();
		}});
	}

		private openView(evt: egret.TouchEvent): void {
		let viewName: string = "";
		let layType: number = LayerType.UI;
		let data = null;
		switch (evt.currentTarget) {
			case this.giftGroup:
				layType = LayerType.POP;
				viewName = ViewConst.FULIVIEW
				data = 1;
				break;

		}
		if (viewName!="") {
			zysx.LayerMgr.ins.openView(viewName, data, layType);
		}
	}
	public next():void{
		zysx.LayerMgr.ins.openView(ViewConst.PLAYVIEW,1,LayerType.UI);
		this.closeSelf();
	}

	public onClose(): void {
		super.onClose();
	}
}
window["SuccessView"] = SuccessView;